Search in your own reviews on "Mine dommer" #152
Merged
+911
−150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #131
What
Users can find a review by the wine's name or a word in the comment.
User.reviewsgets asearchargument. Every word must be in the wine's name or in the comment, in any order. Like the wine search, it ignores case and accents: «rose» finds «Rosé», and «å» counts as «a», while «æ» and «ø» are letters of their own.%and_are plain characters, andtotalCountcounts only the hits./mine/dommer. It searches after a 300 ms pause, or at once on Enter.?q=, the same name as on the search page. Search and order keep each other, and both survive a reload and «Tilbake til Mine dommer» from a wine.How
Backend
review-query.ts, likewine-query.tsandlists/list-query.ts. It reusestoSearchWords,escapeLikeandaddParam, which are now exported.list-query.tsuses the sharedaddParaminstead of its own copy.toSearchTextfolds the words in JavaScript (normalize(…, NFD), accents removed, lowercase), once per review with aLATERAL. I compared the two in PostgreSQL.review_user_idfinds the user's reviews, and only those are compared.Frontend
useDebouncedUrlText: a new shared hook for a search field whose search lives in the URL. The search page'suseSearchTextnow uses it, with the same behaviour as before.useDebouncedValue:mainnow also hasuseDebouncedValue, used for the suggestions. It debounces a value, not a write to the URL. I did not build on it, as a lagging value could write an old search back into the URL after the back button changes it.keyArgsforUser.reviewsis now['order', 'search']. Without a search, the reviews still share the cache with «Min side».[a-z0-9=&-]in the query, so a search like?q=r%C3%B8d+lamfell back to «Utforsk alle viner». It now accepts what an encoded query holds, but still no/,:or<. The tests for invalid targets are extended.Fix of a race that was already on main
On a busy machine,
search.spec.tsturned «pinot» into «pnot». The hook's own URL change could arrive late, after the user had typed on, and was then taken for a change from outside, which reset the field. This was already inuseSearchTextonmain. The hook now remembers what it wrote, and only follows URL changes from outside (a link, the back button).useDebouncedUrlText.test.tsxreproduces the race by holding the URL write back, with fake timers, so it does not depend on machine speed.Tests
review-query.test.ts(no database):%and_escapedreview-api.db.test.ts:%and_as plain characters, and a blank searchMyReviewsPage.test.tsx:useDebouncedUrlText.test.tsx:apollo.test.ts: each search is cached apart, and the reviews without a search are stored where «Min side» finds them.WinePage.test.tsx: the back link with a search in the URL, and more invalid targets.e2e/profile.spec.ts: search on «Mine dommer», kept in the URL, after a reload and back from a wine, with no axe violations. It usesfill, not arrow keys, so it runs the same on macOS. The fake API can now search the reviews.Docs
docs/api.md:searchonUser.reviewswith an example query, how the text is folded, anduseDebouncedUrlTextin the «Min side» table.docs/manual-testing.md: five new steps.main), and the «Min side» row.How to test
npm run check,TEST_DATABASE_URL=… npm testinbackend/, andnpx playwright test e2e/profile.spec.ts e2e/search.spec.tsinfrontend/.demo(afternpm run db:seed:demo) and open/mine/dommer.LAM. It finds «… perfekt til lam.»,?q=LAMis in the URL, and focus stays in the field./sok: the search works as before, also with fast typing.Review notes
npm ci --prefix frontendafter pullingmain(Downshift).main:landing.spec.ts(frommain, not touched here) timed out a few times under heavy load: the axe test and the search from the landing page on mobile. With--workers=1 --repeat-each=10it passed every time.curlmay not sendøas UTF-8. Use\u00f8in the query, or test in the browser.search.spec.ts«sender bare ett søk …» independent of machine speed withpage.clock. It sent an extra search when a key took more than 300 ms under load.AI
Claude used to generate code and tests based on prompts. Implemented and tested manually. Claude used to create initial PR text for easy summary, review and added to manually afterwards.